from typing import *
from math import inf


class Solution:
    def maximumTotalCost(self, nums: List[int]) -> int:
        a, b = 0, -inf
        for i, num in enumerate(nums):
            ai = a
            a = max(b + num, a + num)
            if i > 0:
                b = ai - num
        return max(a, b)


s = Solution()
print(s.maximumTotalCost(nums=[-1]))
print(s.maximumTotalCost(nums=[1, -2, 3, 4]))
print(s.maximumTotalCost(nums=[1, -1, 1, -1]))
print(s.maximumTotalCost(nums=[1, 2, -3, -4, 5]))
